package com.zhiming.item.cotroller;

import com.zhiming.item.pojo.Advisory;
import com.zhiming.item.service.AdvisoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户咨询 Controller
 */

@RestController
public class AdvisoryController {
    @Autowired(required = false)
    private AdvisoryService advisoryService;

    /**
     * 根据id查询咨询信息
     */
    @GetMapping("/advisory/{id}")
    public ResponseEntity<Advisory> findById(@PathVariable("id") Integer id){
        Advisory advisory = advisoryService.findById(id);
        return ResponseEntity.ok(advisory);
    }

    /**
     * 查询所有信息
     */
    @GetMapping("/advisory/findAll")
    public ResponseEntity<List<Advisory>> findAll(){
        List<Advisory> advisoryList = advisoryService.findAll();
        return ResponseEntity.ok(advisoryList);
    }


    /**
     *新增咨询信息
     */
    @PostMapping("/advisory")
    public ResponseEntity<Void> saveAdvisory(Advisory advisory){
        advisoryService.saveAdvisory(advisory);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    /**
     *删除咨询信息
     */
    @DeleteMapping("/advisory/{id}")
    public ResponseEntity<Void> deleteAdvisory(@PathVariable("id") Integer id){
        advisoryService.deleteAdvisory(id);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    /**
     *修改咨询信息
     */
    @PutMapping("/advisory")
    public ResponseEntity<Void> updateAdvisory(Advisory advisory){
        advisoryService.updateAdvisory(advisory);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }



}
